			TABBY									=	2>&1 | sed -e 's/./\t&/'

override	CPPFLAGS								+=	-Wall -Wpointer-arith -Werror
override	CPPFLAGS								+=	-Iv8/include
override	CPPFLAGS								+=	-I.

			LIBRARIES								=	-lv8
override	LIBRARIES								+=	-lstdc++

			CGI_BIN									=	/usr/lib/cgi-bin

			COUNTERPART_LIBRARIES					=	$(LIBRARIES)
override	COUNTERPART_LIBRARIES					+=	-lfcgi
override	COUNTERPART_LIBRARIES					+=	-ldl

			COUNTERPART								=	counterpart
			COUNTERPART_OBJECTS						=	$(COUNTERPART).o
			COUNTERPART_TARGET						=	$(COUNTERPART)
			COUNTERPART_INSTALL_DIRECTORY			=	$(CGI_BIN)/$(COUNTERPART)

			OBJECTS									=	$(COUNTERPART)Exceptions.o
override	OBJECTS									+=	$(COUNTERPART)FormatString.o

			EXTENSION								=	extension
			EXTENSION_OBJECTS						=	$(COUNTERPART)Exceptions.o
override	EXTENSION_OBJECTS						+=	$(COUNTERPART)FormatString.o
			EXTENSION_LDFLAGS						=	$(LDFLAGS)
override	EXTENSION_LDFLAGS						+=	-shared
			EXTENSIONS_DIRECTORY					=	$(EXTENSION)s
			EXTENSIONS_ORG_DIRECTORY				=	$(EXTENSIONS_DIRECTORY)/org
			EXTENSIONS_ORG_ICONGARDEN_DIRECTORY		=	$(EXTENSIONS_ORG_DIRECTORY)/icongarden

			FILE_SYSTEM_LIBRARIES					=	$(LIBRARIES) $(EXTENSION_OBJECTS)
			FILE_SYSTEM_DIRECTORY					=	$(EXTENSIONS_ORG_ICONGARDEN_DIRECTORY)/fileSystem
			FILE_SYSTEM_OBJECTS						=	$(FILE_SYSTEM_DIRECTORY)/$(EXTENSION).o
			FILE_SYSTEM_TARGET						=	$(FILE_SYSTEM_DIRECTORY)/$(EXTENSION).so

			HELLO_LIBRARIES							=	$(LIBRARIES)
			HELLO_DIRECTORY							=	$(EXTENSIONS_ORG_ICONGARDEN_DIRECTORY)/hello
			HELLO_OBJECTS							=	$(HELLO_DIRECTORY)/$(EXTENSION).o
			HELLO_TARGET							=	$(HELLO_DIRECTORY)/$(EXTENSION).so

			HTTP_LIBRARIES							=	$(LIBRARIES) $(EXTENSION_OBJECTS)
			HTTP_DIRECTORY							=	$(EXTENSIONS_ORG_ICONGARDEN_DIRECTORY)/http
			HTTP_OBJECTS							=	$(HTTP_DIRECTORY)/$(EXTENSION).o
			HTTP_TARGET								=	$(HTTP_DIRECTORY)/$(EXTENSION).so

			ENV_LIBRARIES							=	$(LIBRARIES) $(EXTENSION_OBJECTS)
			ENV_DIRECTORY							=	$(EXTENSIONS_ORG_ICONGARDEN_DIRECTORY)/env
			ENV_OBJECTS								=	$(ENV_DIRECTORY)/$(EXTENSION).o
			ENV_TARGET								=	$(ENV_DIRECTORY)/$(EXTENSION).so

default : $(COUNTERPART) $(FILE_SYSTEM_TARGET) $(HELLO_TARGET) $(HTTP_TARGET) $(ENV_TARGET)

$(COUNTERPART_TARGET) : $(COUNTERPART_OBJECTS) $(OBJECTS)
	$(CC) $^ $(COUNTERPART_LIBRARIES) $(LDFLAGS) -o $@ $(TABBY)

$(FILE_SYSTEM_TARGET) : $(FILE_SYSTEM_OBJECTS)
	$(CC) $^ $(FILE_SYSTEM_LIBRARIES) $(EXTENSION_LDFLAGS) -o $@ $(TABBY)

$(ENV_TARGET) : $(ENV_OBJECTS)
	$(CC) $^ $(ENV_LIBRARIES) $(EXTENSION_LDFLAGS) -o $@ $(TABBY)

$(HELLO_TARGET) : $(HELLO_OBJECTS)
	$(CC) $^ $(HELLO_LIBRARIES) $(EXTENSION_LDFLAGS) -o $@ $(TABBY)

$(HTTP_TARGET) : $(HTTP_OBJECTS)
	$(CC) $^ $(HTTP_LIBRARIES) $(EXTENSION_LDFLAGS) -o $@ $(TABBY)

v8/libv8.so :
	cd v8 ; scons mode=release library=shared $(TABBY)
v8/libv8_g.so :
	cd v8 ; scons mode=debug library=shared $(TABBY)
v8-install : v8/libv8.so v8/libv8_g.so
	sudo install -p -v --owner root --group root v8/libv8.so v8/libv8_g.so /usr/lib $(TABBY)

debug :
	$(MAKE) CPPFLAGS="-g -DDEBUG" LIBRARIES=-lv8_g
release :
	$(MAKE) CPPFLAGS="-O3"

clean :
	sudo rm -fv $(COUNTERPART) $(TABBY)
	find . -type f \( -name \*.o -or -name \*.so \) -print | xargs rm -v $(TABBY)

uninstall:
	sudo rm -rf $(COUNTERPART_INSTALL_DIRECTORY) $(TABBY)

install : default uninstall
	sudo rm -rf install  $(TABBY)
	mkdir install $(TABBY)
	cp $(COUNTERPART_TARGET) $(COUNTERPART_TARGET).ssjs install $(TABBY)
	cp -R extensions install $(TABBY)
	find install/extensions -type d -name .svn -print | xargs rm -r $(TABBY)
	find install/extensions -type f -not -name extension.js -not -name extension.so -print | xargs rm $(TABBY)
	find install/extensions -type d | xargs chmod -v a=rx $(TABBY)
	find install/extensions -type f | xargs chmod -v a=r $(TABBY)
	sudo chown -R root:root install
	sudo chmod -v a=xs install/$(COUNTERPART_TARGET) $(TABBY)
	sudo chmod -v a=r install/$(COUNTERPART_TARGET).ssjs $(TABBY)
	sudo mkdir -v $(CGI_BIN) $(TABBY)
	sudo mv -v install $(COUNTERPART_INSTALL_DIRECTORY) $(TABBY)
